package com.nightsoul.cxf;

import java.net.URLConnection;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.endpoint.ClientImpl;
import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.interceptor.AttachmentOutInterceptor;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.MessageSenderInterceptor;
import org.apache.cxf.interceptor.MessageSenderInterceptor.MessageSenderEndingInterceptor;
import org.apache.cxf.interceptor.BareOutInterceptor;
import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
import org.apache.cxf.interceptor.StaxInInterceptor;
import org.apache.cxf.interceptor.StaxOutInterceptor;
import org.apache.cxf.interceptor.WrappedOutInterceptor;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.policy.PolicyDataEngine;
import org.apache.cxf.transport.http.URLConnectionHTTPConduit;
import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
import org.apache.cxf.ws.policy.PolicyDataEngineImpl;
import org.junit.Test;

import com.nightsoul.cxf.interceptor.in.PreStreamInterceptor;
import com.nightsoul.cxf.interceptor.out.SendInterceptor;

public class ClientTest {
	
	@Test
	public void testEndpoint() throws Exception {
		QName helloName = new QName("http://cxf.nightsoul.com/", "HelloServicePort");
		Service service = Service.create(helloName);
		service.addPort(helloName, SOAPBinding.SOAP11HTTP_BINDING, ServerTest.ADDRESS);
		HelloService helloService = service.getPort(HelloService.class);
		System.out.println(helloService.sayHello("xtayfjpk"));
	}
	
	
	@Test
	public void testJaxWsProxyFactoryBean() throws Exception {
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
		factoryBean.getOutInterceptors().add(new SendInterceptor());
		factoryBean.setAddress(ServerTest.ADDRESS);
		factoryBean.setServiceClass(HelloService.class);
		HelloService helloService = factoryBean.create(HelloService.class);

		System.out.println(helloService.getClass());
		System.out.println(helloService.sayHello("xtayfjpk"));
		System.out.println(factoryBean.getConduitSelector());
		PolicyDataEngine engine = factoryBean.getBus().getExtension(PolicyDataEngine.class);
		System.out.println(engine);
		URLConnectionHTTPConduit uhc;
		MessageSenderEndingInterceptor mei;
		BareOutInterceptor boi;
		SoapOutInterceptor soi;
		AttachmentOutInterceptor aoi;
	}
	
	@Test
	public void testJaxWsClientFactoryBean() throws Exception {
		JaxWsClientFactoryBean bean = new JaxWsClientFactoryBean();
		bean.setAddress(ServerTest.ADDRESS);
		bean.setServiceClass(HelloService.class);
		bean.create().invoke("sayHello", "xtayfjpk");
	}
	
	@Test
	public void testSimpleFrontEnd() {
		ClientProxyFactoryBean factoryBean = new ClientProxyFactoryBean();
		HelloService helloService = factoryBean.create(HelloService.class);
		System.out.println(helloService.sayHello("xtayfjpk"));
	}
	
}
